home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / mui / muibuilder / mb / e / localized_demogencodee / demogencodee.e < prev    next >
Text File  |  1995-02-05  |  7KB  |  190 lines

  1. OPT OSVERSION = 37
  2. OPT PREPROCESS
  3.  
  4.  
  5. ->/////////////////////////////////////////////////////////////////////////////
  6. ->////////////////////////////////////////////////////// External modules /////
  7. ->/////////////////////////////////////////////////////////////////////////////
  8. MODULE 'locale'
  9. MODULE 'muimaster' , 'libraries/mui'
  10. MODULE 'utility/tagitem' , 'utility/hooks'
  11. MODULE 'tools/boopsi' , 'tools/installhook'
  12. MODULE 'icon'
  13.  
  14. MODULE '*GUI'
  15. MODULE '*Locale'
  16.  
  17.  
  18. ->/////////////////////////////////////////////////////////////////////////////
  19. ->/////////////////////////////////////////// Global variable definitions /////
  20. ->/////////////////////////////////////////////////////////////////////////////
  21. DEF dgce    :    PTR TO app_obj            -> look at GUI.em for "app_obj" object
  22. DEF cat        :    PTR TO catalog_DemoGenCodeE    -> look at Locale.e for "catalog_DemoGenCodeE" object
  23. DEF string_var    :    PTR TO CHAR            -> used by a notification (see GUI.em, lines 49 and 155)
  24.  
  25.  
  26. ->/////////////////////////////////////////////////////////////////////////////
  27. ->//////////////////////////////////////////////////////// Main Procedure /////
  28. ->/////////////////////////////////////////////////////////////////////////////
  29. PROC main() HANDLE
  30.  
  31.     DEF running = TRUE , result_domethod , signal
  32.     DEF arexx : app_arexx , display : app_display
  33.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  34.     DEF icon = NIL
  35.  
  36.         -> localization init
  37.     localebase := OpenLibrary( 'locale.library' , 0 )
  38.     NEW cat.create()    -> see Locale.e
  39.     cat.open( NIL , NIL )    -> see Locale.e
  40.  
  41.         -> needed libraries and icon init
  42.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Throw( "LIB" , "muim" )
  43.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Throw( "LIB" , "icon" )
  44.  
  45.         -> exported variables init
  46.     string_var := cat.msg_String_Variable_Put.getstr()
  47.  
  48.         -> MUI GUI init
  49.             -> in GUI.em line 22, you can see the declaration of "app_display" object
  50.             -> each field of this object correspond to a hook function declared in MUIBuilder
  51.             -> in the present case, there is only the "button_pressed" hook function (see GUI.em line 167)
  52.     installhook( display.button_pressed , {button_pressed} )
  53.  
  54.         -> ARexx init
  55.             -> for ARexx init you must fill an "app_arexx" object defined in GUI.em line 17
  56.             -> this object gets 2 fields : one for the commands and one for the arexx error hook function
  57.     installhook( change_text_hook , {change_text} )
  58.     arexx.commands := NEW arexx_commands[ 2 ]
  59.     arexx.commands[].mc_name := 'change_text'
  60.     arexx.commands[].mc_template := ''
  61.     arexx.commands[].mc_parameters := 0
  62.     arexx.commands[].mc_hook := change_text_hook
  63.     installhook( arexx.error , {arexx_error} )
  64.  
  65.         -> MUI application creation
  66.             -> for this you call the create method (see GUI.em line 57) on the "app_obj" object
  67.             -> to this method, you must give the "app_display" object
  68.             -> and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete)
  69.     NEW dgce
  70.     IF dgce.create( display , icon , arexx ) = NIL THEN Throw( "MUI" , Mui_Error() )
  71.     dgce.init_notifications( display )
  72.  
  73.         -> Main loop
  74.     WHILE running
  75.  
  76.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  77.         SELECT result_domethod
  78.  
  79.             CASE ID_BUTTON_PRESSED    -> see GUI.em line 42 for the definition of this ID
  80.  
  81.                 set( dgce.tx_result , MUIA_Text_Contents , cat.msg_Modified_ID_Returned.getstr() )
  82.  
  83.             CASE MUIV_Application_ReturnID_Quit
  84.  
  85.                 running := FALSE
  86.  
  87.         ENDSELECT
  88.  
  89.         IF ( signal AND running ) THEN Wait( signal )
  90.  
  91.     ENDWHILE
  92.  
  93. EXCEPT DO
  94.  
  95.     SELECT exception
  96.  
  97.         CASE "LIB"
  98.  
  99.             SELECT exceptioninfo
  100.  
  101.                 CASE "muim"
  102.  
  103.                     error_simple( cat.msg_Missing_Muimaster_Library.getstr() )
  104.  
  105.                 CASE "icon"
  106.  
  107.                     error_simple( cat.msg_Missing_Icon_Library.getstr() )
  108.  
  109.             ENDSELECT
  110.  
  111.         CASE "MEM"
  112.  
  113.             error( cat.msg_Not_Enough_Memory.getstr() )
  114.  
  115.         CASE "MUI"
  116.  
  117.             SELECT exceptioninfo
  118.  
  119.                 CASE MUIE_OutOfMemory
  120.  
  121.                     error_simple( cat.msg_Not_Enough_Memory.getstr() )
  122.  
  123.                 CASE MUIE_OutOfGfxMemory
  124.  
  125.                     error_simple( cat.msg_Not_Enough_Chip_Memory.getstr() )
  126.  
  127.                 CASE MUIE_MissingLibrary
  128.  
  129.                     error_simple( cat.msg_Missing_Library.getstr() )
  130.  
  131.                 CASE MUIE_NoARexx
  132.  
  133.                     error_simple( cat.msg_Arexx_Port.getstr() )
  134.  
  135.                 DEFAULT
  136.  
  137.                     error_simple( cat.msg_Internal_Problem.getstr() )
  138.  
  139.             ENDSELECT
  140.  
  141.     ENDSELECT
  142.  
  143.     IF dgce            THEN dgce.dispose()
  144.     IF icon            THEN FreeDiskObject( icon )
  145.     IF iconbase        THEN CloseLibrary( iconbase )
  146.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  147.     cat.close()
  148.     IF localebase        THEN CloseLibrary( localebase )
  149.  
  150. ENDPROC
  151.  
  152.  
  153. ->/////////////////////////////////////////////////////////////////////////////
  154. ->/////////////////// Prints an error message with an intuition requester /////
  155. ->/////////////////////////////////////////////////////////////////////////////
  156. PROC error_simple( message : PTR TO CHAR ) IS EasyRequestArgs(    NIL , [ 20 , 0 ,
  157.                                     cat.msg_DGCE_Error.getstr() ,
  158.                                     message ,
  159.                                     cat.msg_Simple_OK.getstr() ] , NIL , NIL )
  160.  
  161.  
  162. ->/////////////////////////////////////////////////////////////////////////////
  163. ->///////////////////////// Prints an error message with an MUI requester /////
  164. ->/////////////////////////////////////////////////////////////////////////////
  165. PROC error( message : PTR TO CHAR ) IS Mui_RequestA(    dgce.app ,
  166.                             dgce.wi_the_window ,
  167.                             NIL ,
  168.                             cat.msg_DGCE_Error.getstr() ,
  169.                             cat.msg_OK.getstr() ,
  170.                             message ,
  171.                             NIL )
  172.  
  173.  
  174. ->/////////////////////////////////////////////////////////////////////////////
  175. ->///////// Hook function called each time bt_call_hook button is pressed /////
  176. ->/////////////////////////////////////////////////////////////////////////////
  177. PROC button_pressed( hook , obj , msg ) IS set( dgce.tx_result , MUIA_Text_Contents , cat.msg_Modified_By_Hook.getstr() )
  178.  
  179.  
  180. ->/////////////////////////////////////////////////////////////////////////////
  181. ->///////////////////// Hook function called by ARexx command change_text /////
  182. ->/////////////////////////////////////////////////////////////////////////////
  183. PROC change_text( hook , obj , msg ) IS set( dgce.tx_result , MUIA_Text_Contents , cat.msg_Modified_By_Arexx.getstr() )
  184.  
  185.  
  186. ->/////////////////////////////////////////////////////////////////////////////
  187. ->//////////////////////// Hook function called by ARexx in case of error /////
  188. ->/////////////////////////////////////////////////////////////////////////////
  189. PROC arexx_error( hook , obj , msg ) IS error_simple( cat.msg_Unknown_ARexx_Command.getstr() )
  190.